
 /**
 * GroupManagerImpl.java.java.
 * User: BrianChen Date: 2012-6-7 下午10:23:07
 *
 * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
 * All rights reserved.
 */
package com.collapsar.core.security.service.impl;

import com.collapsar.core.security.dao.IGroupDao;
import com.collapsar.core.security.dao.IRoleDao;
import com.collapsar.core.security.dao.IUserDao;
import com.collapsar.core.security.model.Group;
import com.collapsar.core.security.model.User;
import com.collapsar.core.security.service.IGroupManager;
import com.collapsar.core.service.BaseUserAwareManager;

/**
 * <pre>
 * REVISIONS: 
 * Version 	Date 		Author 			Description
 * ------------------------------------------------------------------- 
 * 1.0 		2012-6-7 	BrianChen 	1. Created this class. 
 * </pre>
 * 
 * @author BrianChen
 * @date 2012-6-7 下午10:23:07
 * @version 1.0
 * @see
 * 
 */
public class GroupManagerImpl extends BaseUserAwareManager implements IGroupManager{
	private IGroupDao groupDao = null;
	private IRoleDao roleDao = null;
	private IUserDao userDao = null;
	
	@Override
	public void storeGroup(Group group) {
		this.groupDao.storeGroup(group);
	}

	@Override
	public void deleteGroup(Long groupId) {
		this.groupDao.deleteGroup(groupId);
	}

	@Override
	public void deleteAllGroups(Long[] groupIds) {
		this.groupDao.deleteAllGroups(groupIds);
	}

	@Override
	public Group loadGroup(Long groupId) {
		return this.groupDao.loadGroup(groupId);
	}

//	@Override
//	public Group loadGroupWithRoles(Long groupId) {
//		return this.groupDao.loadGroupWithRoles(groupId);
//	}

	@Override
	public Group loadGroupWithUsers(Long groupId) {
		return this.groupDao.loadGroupWithUsers(groupId);
	}

	@Override
	public Group loadGroupWithRolesAndUsers(Long groupId) {
		return this.groupDao.loadGroupWithRolesAndUsers(groupId);
	}

//	@Override
//	public void addRoles(Long[] roleIds, Long groupId) {
//		Group group = this.groupDao.loadGroupWithRoles(groupId);
//		for(Long roleId : roleIds){
//			Role role = this.roleDao.loadRole(roleId);
//			group.addRole(role);
//		}
//		this.groupDao.storeGroup(group);
//	}
//
//	@Override
//	public void deleteRoles(Long[] roleIds, Long groupId) {
//		Group group = this.groupDao.loadGroupWithRoles(groupId);
//		for(Long roleId : roleIds){
//			Role role = this.roleDao.loadRole(roleId);
//			group.deleteRole(role);
//		}
//		this.groupDao.storeGroup(group);
//	}

	@Override
	public void addUsers(Long[] userIds, Long groupId) {
		Group group = this.groupDao.loadGroupWithUsers(groupId);
		for(Long userId : userIds){
			User user = this.userDao.loadUser(userId);
			group.addUser(user);
		}
		this.groupDao.storeGroup(group);
	}

	@Override
	public void deleteUsers(Long[] userIds, Long groupId) {
		Group group = this.groupDao.loadGroupWithUsers(groupId);
		for(Long userId : userIds){
			User user = this.userDao.loadUser(userId);
			group.deleteUser(user);
		}
		this.groupDao.storeGroup(group);
	}

	public IGroupDao getGroupDao() {
		return groupDao;
	}

	public void setGroupDao(IGroupDao groupDao) {
		this.groupDao = groupDao;
	}

	public IRoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(IRoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}
	
	

}

